package com.small.mybatis.type;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

/**
 * @Author zhoujin
 * @Date 2022/4/27 19:42
 */
public class TypeAliasRegistry {

    private final Map<String,Class<?>> TYPE_ALIASES = new HashMap();

    public TypeAliasRegistry() {

        // 构造函数里注册系统内置的类型别名
        registerAlias("string", String.class);

        // 基本包装类型
        registerAlias("byte", Byte.class);
        registerAlias("long", Long.class);
        registerAlias("short", Short.class);
        registerAlias("int", Integer.class);
        registerAlias("integer", Integer.class);
        registerAlias("double", Double.class);
        registerAlias("float", Float.class);
        registerAlias("boolean", Boolean.class);

    }


    public void registerAlias(String alias,Class<?> value){
        String key = alias.toLowerCase(Locale.ENGLISH);
        TYPE_ALIASES.put(key,value);
    }

    public Class resolveAlias(String alias){
        String key = alias.toLowerCase(Locale.ENGLISH);
        return TYPE_ALIASES.get(key);
    }

}
